package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.shop.ShopShippingTemplateDto;
import com.java110.po.shop.ShopShippingTemplatePo;
import com.java110.mall.shop.bmo.shopShippingTemplate.IDeleteShopShippingTemplateBMO;
import com.java110.mall.shop.bmo.shopShippingTemplate.IGetShopShippingTemplateBMO;
import com.java110.mall.shop.bmo.shopShippingTemplate.ISaveShopShippingTemplateBMO;
import com.java110.mall.shop.bmo.shopShippingTemplate.IUpdateShopShippingTemplateBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/shopShippingTemplate")
public class ShopShippingTemplateApi {

    @Autowired
    private ISaveShopShippingTemplateBMO saveShopShippingTemplateBMOImpl;
    @Autowired
    private IUpdateShopShippingTemplateBMO updateShopShippingTemplateBMOImpl;
    @Autowired
    private IDeleteShopShippingTemplateBMO deleteShopShippingTemplateBMOImpl;

    @Autowired
    private IGetShopShippingTemplateBMO getShopShippingTemplateBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopShippingTemplate/saveShopShippingTemplate
     * @path /app/shopShippingTemplate/saveShopShippingTemplate
     */
    @RequestMapping(value = "/saveShopShippingTemplate", method = RequestMethod.POST)
    public ResponseEntity<String> saveShopShippingTemplate(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "name", "请求报文中未包含name");
        Assert.hasKeyAndValue(reqJson, "templateType", "请求报文中未包含templateType");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");


        ShopShippingTemplatePo shopShippingTemplatePo = BeanConvertUtil.covertBean(reqJson, ShopShippingTemplatePo.class);
        return saveShopShippingTemplateBMOImpl.save(shopShippingTemplatePo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopShippingTemplate/updateShopShippingTemplate
     * @path /app/shopShippingTemplate/updateShopShippingTemplate
     */
    @RequestMapping(value = "/updateShopShippingTemplate", method = RequestMethod.POST)
    public ResponseEntity<String> updateShopShippingTemplate(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "name", "请求报文中未包含name");
        Assert.hasKeyAndValue(reqJson, "templateType", "请求报文中未包含templateType");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");
        Assert.hasKeyAndValue(reqJson, "templateId", "templateId不能为空");


        ShopShippingTemplatePo shopShippingTemplatePo = BeanConvertUtil.covertBean(reqJson, ShopShippingTemplatePo.class);
        return updateShopShippingTemplateBMOImpl.update(shopShippingTemplatePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /shopShippingTemplate/deleteShopShippingTemplate
     * @path /app/shopShippingTemplate/deleteShopShippingTemplate
     */
    @RequestMapping(value = "/deleteShopShippingTemplate", method = RequestMethod.POST)
    public ResponseEntity<String> deleteShopShippingTemplate(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "templateId", "templateId不能为空");


        ShopShippingTemplatePo shopShippingTemplatePo = BeanConvertUtil.covertBean(reqJson, ShopShippingTemplatePo.class);
        return deleteShopShippingTemplateBMOImpl.delete(shopShippingTemplatePo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 小区ID
     * @return
     * @serviceCode /shopShippingTemplate/queryShopShippingTemplate
     * @path /app/shopShippingTemplate/queryShopShippingTemplate
     */
    @RequestMapping(value = "/queryShopShippingTemplate", method = RequestMethod.GET)
    public ResponseEntity<String> queryShopShippingTemplate(@RequestParam(value = "shopId") String shopId,
                                                            @RequestParam(value = "page") int page,
                                                            @RequestParam(value = "row") int row) {
        ShopShippingTemplateDto shopShippingTemplateDto = new ShopShippingTemplateDto();
        shopShippingTemplateDto.setPage(page);
        shopShippingTemplateDto.setRow(row);
        shopShippingTemplateDto.setShopId(shopId);
        return getShopShippingTemplateBMOImpl.get(shopShippingTemplateDto);
    }
}
